<html>

<head>
    <meta charset="utf-8">
    <title>新增角色</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/${BasePath}/static/layui/css/layui.css" media="all" type="text/css">
    <link rel="stylesheet" href="/${BasePath}/static/css/public.css" media="all" type="text/css"> </head>
    <link rel="stylesheet" href="/${BasePath}/static/layui/css/modules/tree/eleTree.css" media="all" type="text/css"> 
    </head>
<body class="childrenBody">
 
    <form id="actionForm" class="layui-form" lay-filter="example">
        <input type="hidden" name="id" id="id" value="${sRole.id!'0'}">
        <input type="hidden" name="permissionId" id="permissionId" value="">
        <div class="layui-col-md6 layui-col-xs12">
        	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
			  <legend>角色信息</legend>
			</fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">角色名称</label>
                <div class="layui-input-block">
                    <input type="text" name="roleName" lay-verify="required" placeholder="请输入角色名称" class="layui-input realName" value="${sRole.roleName!''}"> </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">角色说明</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="roleSynopsis" lay-verify="required" name="roleSynopsis" class="layui-textarea myself">${sRole.roleSynopsis!''}</textarea>
                </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
			  <legend>权限设置</legend>
			</fieldset>
            <div class="layui-form-item">
            <label class="layui-form-label">设置权限</label>
                <div class="layui-input-block ele1">
                </div>
            </div>
            
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" type="button" lay-filter="form">立即提交</button>
                </div>
            </div>
       </div>
    </form>
    <script src="/${BasePath}/static/layui/layui.js" charset="utf-8" type="text/javascript"></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common/jquery-2.1.0.min.js"></script>
    <script type="text/javascript">
    layui.config({
        base : "/${BasePath}/static/layui/lay/myModules/"
    }).extend({
        'eleTree' : 'eleTree'
    })
    layui.use(['form','eleTree'], function() {
        var form = layui.form,
            eleTree = layui.eleTree,
            layer = layui.layer;

        /* 权限 */
        var obj={
                elem: '.ele1',
                url: "/${BasePath}/power/getMemRole",
                renderAfterExpand: true,
                expandOnClickNode: true,
                showCheckbox:true,
                defaultCheckedKeys:${permissionIds!'[]'}
            }
            var el1=eleTree.render(obj);
        form.on('submit(form)', function() {
        	var chick = el1.getChecked(true,false);
        	var chickId = new Array();
        	for(var i=0;i<chick.length;i++){
        		chickId.push(chick[i].key);
        	}
        	console.log(chickId);
        	$("#permissionId").val(chickId)
            $.ajax({
                cache: true,
                type: "POST",
                url: "/${BasePath}/power/saveUpRole",
                data: $('#actionForm').serialize(),
                async: false,
                error: function(request) {
                    layer.msg('系统错误！');
                },
                success: function(data) {
                    if(data.code = "1") {
                        layer.msg(data.msg, {
                            time: 1000
                        }, function() { //提示框设定显示1秒
                        	window.location.href="/${BasePath}/power/roleList"; 
                        })
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
        });
    });
    </script>
</body>

</html>